import request from '@/utils/request'

export interface WarehouseInfo {
  warehouseId: number
  warehouseName: string
  location: string
  capacity: number
  status: boolean
  managerId: number
  manager: {
    userId: number
    username: string
    realName: string
  }
  createdAt: string
  updatedAt: string
}

export interface CreateWarehouseParams {
  warehouseName: string
  location: string
  capacity: number
  managerId: number
  status: number
}

export interface UpdateWarehouseParams extends CreateWarehouseParams {
  warehouseId: number
}

export interface WarehouseListParams {
  pageNum: number
  pageSize: number
  warehouseName?: string
}

export interface WarehouseListResponse {
  list: WarehouseInfo[]
  total: number
}

const warehouseApi = {
  getWarehouseList(params: WarehouseListParams) {
    return request.get<WarehouseListResponse>('/warehousesInfo', { params })
  },

  createWarehouse(data: CreateWarehouseParams) {
    return request.post<WarehouseInfo>('/createWarehouses', data)
  },

  getWarehouseById(id: number) {
    return request.get<WarehouseInfo>(`/warehouseById/${id}`)
  },

  updateWarehouse(id: number, data: CreateWarehouseParams) {
    return request.put<WarehouseInfo>(`/updateWarehouse/${id}`, data)
  },

  deleteWarehouse(id: number) {
    return request.delete(`/deleteWarehouse/${id}`)
  }
}

export default warehouseApi